/**
 * @file filter
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import * as React from 'react';
import {
  Component,
  PropTypes
} from 'react';
import {render} from '../../renderer';
import {
  ButtonToolbar,
  FormGroup
} from 'react-bootstrap';
import * as assign from 'object-assign';
import * as cx from 'classnames';
import * as omit from 'lodash/omit';
import {Enhance as FormItem} from '../form-item';

@FormItem({
  type:'button-toolbar',
  attachForm: false,
  haveLabel: false,
  validateSchema: 'http://amis.baidu.com/schemas/form.json#/definitions/buttonToolbar'
})
export default class FormButtonToolbar extends Component {
  static propTypes = {
    className: PropTypes.string,
    type: PropTypes.string.isRequired,
    buttons: PropTypes.arrayOf(PropTypes.object)
  };

  render() {
    const {
      $path,
      buttons
    } = this.props;

    return (
      <ButtonToolbar>
        {buttons.map((button, index) => button.type === 'button-group'
          ? render(`${$path}/form-item`, button, assign(omit(this.props, ['className', 'type', 'buttons']), {
            haveAllElements: false,
            key: index
          }))
          : render(`${$path}/action`, button, assign(omit(this.props, ['className', 'type', 'buttons']), {
            key: index
          })))}
      </ButtonToolbar>
    );
  }
}
